//package com.zyf.cloud.common.utils;
//
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//
//public class IpUtils {
//
//	/**
//	 * 返回用户的IP地址
//	 *
//	 * @param request
//	 * @return
//	 */
//	public static String toIpAddr(HttpServletRequest request) {
//		if (request == null) {
//			return "";
//		}
//		String ip = request.getHeader("X-Forwarded-For");
//
//		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//			ip = request.getHeader("Proxy-Client-IP");
//		}
//		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//			ip = request.getHeader("WL-Proxy-Client-IP");
//		}
//		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//			ip = request.getHeader("HTTP_CLIENT_IP");
//		}
//		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//			ip = request.getHeader("HTTP_X_FORWARDED_FOR");
//		}
//		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//			ip = request.getRemoteAddr();
//		}
//
//		if (ip != null && ip.indexOf(",") != -1) {
//			String[] ipWithMultiProxy = ip.split(",");
//			for (String eachIpSegement : ipWithMultiProxy) {
//				if (!"unknown".equalsIgnoreCase(eachIpSegement)) {
//					ip = eachIpSegement;
//					break;
//				}
//			}
//		}
//		return ip;
//	}
//
//	/**
//	 * 返回用户的IP地址
//	 *
//	 * @return
//	 */
//	public static String toIpAddr() {
//		return toIpAddr(getRequest());
//	}
//
//	/**
//	 * 返回request
//	 *
//	 * @return
//	 */
//	public static HttpServletRequest getRequest() {
//		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//	}
//}
